package com.ssm.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/common/requirejs")
public class RequirejsDemoController {
	private static final Logger logger = LoggerFactory.getLogger(RequirejsDemoController.class);

	/**
	 * 
	 * "demoWithJquery.jsp"
	 * app.js,main.js,jquery.alpha.js,jquery.beta.js
	 * 摘抄自： 
	 * https://github.com/requirejs/example-jquery-shim
	 * 
	 * https://github.com/requirejs/example-jquery-cdn
	 * 以上链接使用的样例源码和"example-jquery-shim"差不多,只是使用的是CDN
	 * 
	 * 
	 * @param request
	 * @param response
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "/demoWithJquery", method = { RequestMethod.POST, RequestMethod.GET })
	public String demoWithJquery(HttpServletRequest request, HttpServletResponse response, ModelMap map) {
		logger.info("demoWithJquery");
		return "requirejs/demoWithJquery";
	}
	
	/**
	 * 
	 * 引入 "text.js", "domReady.js"
	 * 
	 * "text_demo.js"是测试这个功能的代码
	 * define(["text!textpath/aa.html"], function(aa) { ...
	 * `text!textpath/aa.html`
	 * 
	 * @param request
	 * @param response
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "/loadText", method = { RequestMethod.POST, RequestMethod.GET })
	public String loadText(HttpServletRequest request, HttpServletResponse response, ModelMap map) {
		logger.info("loadText");
		return "requirejs/loadText";
	}

}
